﻿using System;
using System.Text;
namespace Mp3Observer.Common
{
    /// <summary>
    /// Beinhaltet ExtensionMethods für Strings.
    /// </summary>
    public static class Strings
    {
        /// <summary>
        /// Converts a string to base64.
        /// </summary>
        /// <param name="original">The original.</param>
        /// <returns>base64 string</returns>
        public static string ToBase64(this string original)
        {
            if (original == null)
                return null;
            byte[] byt = Encoding.UTF8.GetBytes(original);
            return Convert.ToBase64String(byt);
        }

        /// <summary>
        /// Converts a base64 string into utf8.
        /// </summary>
        /// <param name="original">The base64 original.</param>
        /// <returns>the converted utf8 string</returns>
        public static string FromBase64(this string original)
        {
            if (original == null)
                return null;
            byte[] b = Convert.FromBase64String(original);
            return Encoding.UTF8.GetString(b);
        }

        /// <summary>
        /// Determines whether the input string is null or empty.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <returns>
        ///     <c>true</c> if the specified input is null or empty; otherwise, <c>false</c>.
        /// </returns>
        /// <remarks>
        /// http://petesbloggerama.blogspot.com/2010/03/stringempty-vs-vs-string-isnullorempty.html
        /// </remarks>
        public static bool IsNullOrEmpty(this string input)
        {
            return (input == null || input.Length == 0);
        }
    }
}
